Skip to content

fix(roles): ignore server-generated ids when comparing roles - #1674

Open
RutgerLubbers wants to merge 2 commits into
adorsys:mainfrom
Q24:feat/ignore-role-ids-on-compare
Open

RutgerLubbers wants to merge 2 commits into
adorsys:mainfrom
Q24:feat/ignore-role-ids-on-compare

Conversation

@RutgerLubbers

@RutgerLubbers RutgerLubbers commented Sep 3, 2026 •

Copy link
Copy Markdown

Role change-detection compared the server-assigned id and containerId, so a realm exported from another Keycloak instance made every role look changed and triggered pointless updates. Since Keycloak 26.6.4 those updates fail with HTTP 403 on the admin, create-realm and realm-management roles, aborting the import.

Both identifiers are now excluded from the patch and the equality check for realm and client roles, matching what ClientImportService already does. The existing role's identifiers survive because the patch is built on a clone of it.

Fixes #1672

Role change-detection compared the server-assigned `id` and `containerId`,
so a realm exported from another Keycloak instance made every role look
changed and triggered pointless updates. Since Keycloak 26.6.4 those
updates fail with HTTP 403 on the `admin`, `create-realm` and
`realm-management` roles, aborting the import.

Both identifiers are now excluded from the patch and the equality check
for realm and client roles, matching what ClientImportService already
does. The existing role's identifiers survive because the patch is built
on a clone of it.
@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Comment on lines +218 to 219
RoleRepresentation patchedRole = CloneUtil.patch(existingRole, roleToImport, propertiesToIgnoreOnUpdate);
if (roleToImport.getAttributes() != null) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree that this change is the cause of the underlying analysis.
Further the method is only called if existingRole != null and CloneUtil.patch only returns null if origin (or existingRole in this case) is null.

Comment on lines +237 to 238
RoleRepresentation patchedRole = CloneUtil.patch(existingRole, roleToImport, propertiesToIgnoreOnUpdate);
String roleName = existingRole.getName();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above!

@Motouom Motouom left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @RutgerLubbers, really sorry for the late reply.

Thanks for the implementation. I reviewed the role comparison change and tested it locally.

The code-level behavior looks correct: server-generated id and containerId are ignored for comparisons, genuine role content changes are still applied, and the target instance IDs are preserved. The focused tests and full ./mvnw clean install passed, including Checkstyle, PMD, SpotBugs, and license checks. I also verified the JSON fixtures through the compiled kccli JAR against Docker Keycloak and confirmed the realm/client roles in the Admin Console.

Before this can be approved and merged, please:

  1. Resolve the current merge conflicts with adorsys/main.
  2. Re-run the complete CI pipeline on the updated commit.
  3. Confirm that the current Sonar/quality gate is green; the PR still has a historical Sonar failure recorded.

I did not find an additional functional code defect, but the conflicts and quality-gate status still block approval.

@sonarqubecloud

Copy link
Copy Markdown

@RutgerLubbers

Copy link
Copy Markdown
Author

@Motouom Is this good to go like this?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Role import sends spurious updates because server-generated id/containerId are compared → HTTP 403 on protected roles (Keycloak 26.6.4+)

2 participants